<?php

    function a1(){
        $str = "This is 'some' <b>bold</b> text.";
        //转译为html实体
        echo htmlspecialchars($str);

        echo "<br/>";
        //在预定义字符之前添加反斜杠转义(单引号、双引号、反斜杠) //stripcslashes
        $str1 = addslashes($str);
        echo $str1;
    }
    //a1();

    //分割字符串为数组explode || implode
    function a2(){
        $str = "Hello world. I love Shanghai!";
        $arr = explode(" ",$str);
        print_r($arr);
        print_r(implode(":",$arr));
    }
    //a2();


    //字符替换
    function a3(){
        $arr = array("blue","red","green","yellow");
        print_r(str_replace("red","pink",$arr,$i));
        echo "替换数：$i"."<br/>";
        //字符长度
        echo strlen("123");
    }
    //a3();

    //检索数组匹配 //preg_grep 返回一个数组
    function a4(){
        $foods = array("pasta", "steak", "fish", "potatoes");
        $p_foods = preg_grep("/p(\w+)/", $foods);
        print_r($p_foods);
    }
    //a4();

    //字符检索 --正则表达式如js
    function a5(){
       //不一样的是此模块不能设置g参数并且需要填第三个matches变量 (多次匹配preg_match_all)
        $a = preg_match("/PHP/", "PHP is the web scripting PHP language of choice.",$matches);
        print_r($a);
    }
    //a5();

    //字符替换 --正则表达式如js
    function a6(){
        $string = 'google 123, 456';
        $pattern = '/(\w+) (\d+), (\d+)/i';
        $replacement = 'runoob ${2},$3';
        echo preg_replace($pattern, $replacement, $string);
    }
    //a6();

    /**
     **  日期相关
     **/

    function a7(){
        //Y大写代表四位年 y代表两位年
        //time()获取当前时间戳
        //获取时区
        date_default_timezone_set("Asia/Shanghai");
        echo date('y-m-d H:i:s');
    }
    //a7();

    function a8(){
        //strtotime()函数用于把人类可读的字符串转换为 Unix 时间
        echo date('y-m-d H:i:s',strtotime("2016-06-15 12:12:01"));
    }
    //a8();


    //==============================================

    //is_int() mt_rand(0,10)  range(1,10) 数组范围  count(obj)对象长度

    //each返回第一个键值对数组
    //next先前移再返回
    //reset 指针归位
    //array_count_values 统计数组相同的值出现次数

?>


















